
from DailyBase import *
from AGDefines import *
import logging

logger = logging.getLogger(__name__)



class ZhangHao(DailyBase):

    def __init__(self, enum):
        self.RCName = __name__
        self.LogHeader = self.RCName +str(enum.port)
        self.enum = enum
        self.started = False
        self.findXiTongIcon = False
        self.InputZhangHao = False
        self.loadPrivateActions(self.areaDict, ZhangHaoActions)

        logger.info("{} has {} actions".format(self.LogHeader, len(self.areaDict)))

        self.waitTime = 1.0

    def switchHao(self, zhangHao, mima):
        logger.info(self.LogHeader)
        self.started = True
        self.findXiTongIcon = False
        self.InputZhangHao = False

        data = {"ZhangHao":zhangHao, "MiMa":mima}

        self.begin(data = data, isDaily = False)




    def process_private(self, img = None, data = None):

        logger.info("{} data: {}".format(self.LogHeader, data))

        if self.InputZhangHao ==  True and self.status == STATUS_FEIZHANDOU:
            logger.info("帐号切换 完成")
            self.stop()
            return STATUS_FINISHED

        if self.findXiTongIcon is False:
            if self.areaDict['XiTongIcon'].detect(img) < 10:
                self.enum.click(self.areaDict['XiTongIcon'].click)
                self.findXiTongIcon = True
            else:
                self.enum.click(XianShiTuBiao)

        #QieHuanZhangHao 要在XiTongJieMian之前检测，点击切换以后，在QieHuanZhangHao界面能检测到切换按钮
        if self.areaDict['QieHuanZhangHao'].detect(img) < 10:
            self.enum.click(self.areaDict['QieHuanZhangHao'].click)
        #切换按钮
        elif self.areaDict['XiTongJieMian'].detect(img) < 10:
            self.enum.click(self.areaDict['XiTongJieMian'].click)
        elif self.areaDict['GongGao'].detect(img) < 10:
            self.enum.click(self.areaDict['GongGao'].click)
        elif self.areaDict['DengLuJieMian'].detect(img) < 10:
            if self.InputZhangHao is True:
                self.enum.click(self.areaDict['DengLuJieMian'].click)
            else:
                self.enum.click(HuanHao)

        elif self.areaDict['ShuRuJieMian'].detect(img) < 10:
            self.InputZhangHao = True

            self.enum.click(ZhangHaoKuang, 200)
            for i in range(10):
                self.enum.SendKeyCode('KEYCODE_DEL',30)
            self.enum.putText(data['ZhangHao'])
            self.enum.click(MiMaKuang, 200)
            self.enum.putText(data['MiMa'])
            self.enum.click(self.areaDict['ShuRuJieMian'].click)

        elif self.areaDict['KuaiXun'].detect(img) < 10:
            self.enum.click(self.areaDict['KuaiXun'].click)






